package com.project.common.exception;

import com.project.common.result.ResultCodeEnum;
import lombok.Data;

public class CustomException extends RuntimeException {

    //状态码
    private Integer code;

    public void setCode(Integer code) {
        this.code = code;
    }

    /**
     * 接受状态码和消息
     *
     * @param code 状态码
     * @param message 信息
     */
    public CustomException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    /**
     * 接收枚举类型
     *
     * @param resultCodeEnum 枚举
     */
    public CustomException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    public CustomException(String message) {
        super(message);
        this.code = 2000;
    }

    @Override
    public String toString() {
        return "CustomException{" +
                "code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }
}
